package com.dianrui.qiyouriding.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dianrui.qiyouriding.R;
import com.dianrui.qiyouriding.bean.Datas;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TroubleFeedInfoAdapter extends BaseAdapter {
    List<Datas> list;
    Context context;

    public TroubleFeedInfoAdapter(Context context, List<Datas> list) {
        this.list = list;
        this.context = context;

    }

    public void refresh(List<Datas> list) {
        this.list = list;
        this.notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        if (null != list && list.size() > 0) {
            final Datas datas = list.get(position);
            holder.feedName.setText(datas.name);
            if (datas.isChecked==1) {
                holder.chooseLayout.setBackgroundResource(R.color.green);
                holder.feedName.setTextColor(context.getResources().getColor(R.color.white));
            }
            if (datas.isChecked==0) {
                holder.chooseLayout.setBackgroundResource(R.color.white);
                holder.feedName.setTextColor(context.getResources().getColor(R.color.black));
            }
        }
        return convertView;
    }

     class ViewHolder {
        @BindView(R.id.feed_name)
        TextView feedName;
        @BindView(R.id.choose_layout)
        LinearLayout chooseLayout;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
